<template>
  <view>
    <!-- 导航搜索 -->
    <view class="nav-bar">
      <view class="nav-input">
        <view class="icons-img">
          <image src="http://localhost:3000/static/sousuo.png" mode=""></image>
          <text>搜索品类/单品/风格</text>
        </view>
        <image src="http://localhost:3000/static/xiangji.png" mode=""></image>
      </view>
    </view>
    <!-- 分类菜单 -->
    <view class="menu-list">
      <scroll-view scroll-y="true" class="left-item" :style="{height: wh+ 'px'}" :scroll-top="scrollTop">
        <view :class="['item-name', i === active ? 'active' : '']" v-for="(item,i) in menuList" :key="i"
          @click="activeIndex(i)">
          <text>{{item.menu_name}}</text>
        </view>
      </scroll-view>
      <scroll-view scroll-y="true" class="right-item" :style="{height: wh+ 'px'}">
        <view class="item-img" v-for="(item2,i2) in levelList2" :key="i2" @click="gotoGoodsList(item2,i2)">
          <image :src="item2.menu_img" mode=""></image>
        </view>
      </scroll-view>

    </view>
  </view>
</template>

<script>
  import badgeMix from '@/mixins/tabbar-badge.js'
  export default {
    mixins: [badgeMix],
    data() {
      return {
        menuList: [],
        levelList2: [],
        levelList3: {},
        wh: 0,
        active: 0,
        scrollTop: 0
      };
    },
    methods: {
      // 请求商品数据
      async getMenuList() {
        const {
          data: res
        } = await uni.$http.get('/menu')
        if (res.status !== 200) return uni.showToast({
          title: "数据加载失败！"
        })
        this.menuList = res.data
        this.levelList2 = res.data[0].children
        // console.log(this.levelList2);
      },
      // 点击切换 active
      activeIndex(i) {
        this.active = i
        this.levelList2 = this.menuList[i].children
        this.scrollTop = this.scrollTop === 0 ? 1 : 0
      },
      // 点击条转商品列表
      gotoGoodsList(item, i) {
        const data = JSON.stringify(item.children)
        uni.setStorageSync('item', item.children)
        if (this.active == 0) {
          uni.navigateTo({
            url: "/subpkg/goods_list/goods_list?index=" + this.levelList2[i].title
          })
        } else if (this.active == 1) {
          uni.navigateTo({
            url: '/subpkg/beiou/beiou'
          })
        } else {
          console.log('空间页面');
        }
      }
    },
    onLoad() {
      this.getMenuList()
      // 获取当前系统的信息
      const sysInfo = uni.getSystemInfoSync()
      // 为 wh 窗口可用高度动态赋值
      this.wh = sysInfo.windowHeight - 50

    }
  }
</script>

<style lang="scss">
  // 导航搜索
  .nav-bar {
    position: relative;
    height: 150rpx;
    width: 100%;
    box-sizing: border-box;
    // margin-bottom: 32rpx;

    .nav-input {
      position: absolute;
      bottom: 0;
      display: flex;
      justify-content: space-between;
      left: 24rpx;
      width: 703rpx;
      height: 60rpx;
      box-sizing: border-box;
      padding: 17rpx 24rpx;
      border-radius: 20rpx;
      background-color: #f1f1f1;

      .icons-img {
        width: 100%;
        height: 100%;
        display: flex;
        align-items: center;

        image {
          width: 32rpx;
          height: 32rpx;
          margin-right: 16rpx;
        }

        text {
          font-size: 26rpx;
          color: #dadbdd;
        }
      }

      image {
        width: 32rpx;
        height: 32rpx;
      }
    }
  }

  // 分类列表
  .menu-list {
    display: flex;
    justify-content: space-between;
    padding-right: 24rpx;

    .left-item {
      margin-top: 94rpx;
      white-space: nowrap;

      .item-name {
        box-sizing: border-box;
        margin: 0 56rpx 162rpx 34rpx;
        white-space: nowrap;

        text {
          color: #8a94a1;
          font-size: 30rpx;
        }

        // 激活项的样式
        &.active {
          text {
            color: #232e3d;
          }

          position: relative;

          // 渲染激活项左侧的红色指示边线
          &::before {
            content: '';
            display: block;
            width: 24rpx;
            height: 20rpx;
            background-color: #000065;
            position: absolute;
            left: -31rpx;
            top: 50%;
            margin-right: 10rpx;
            transform: translateY(-50%);
          }
        }
      }

    }

    .right-item {
      margin-top: 32rpx;

      .item-img {
        width: 580rpx;
        height: 170rpx;
        margin-bottom: 20rpx;

        image {
          width: 100%;
          height: 100%;
        }
      }
    }
  }
</style>
